/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

:root {
  --spectrum-accordion-icon-width: 6px;
  --spectrum-accordion-icon-height: 10px;

  /* Subtract the size of the border since it's on the item itself */
  --spectrum-accordion-item-height-actual: calc(var(--spectrum-accordion-item-height) - var(--spectrum-accordion-item-border-size));
  --spectrum-accordion-item-title-tracking-actual: calc(var(--spectrum-accordion-item-title-tracking) / 100);

  --spectrum-accordion-item-title-padding-y: var(--spectrum-global-dimension-size-150);
  --spectrum-accordion-item-line-height: 1.3;

  --spectrum-accordion-item-focus-ring-color: var(--spectrum-alias-focus-color);
}

.spectrum-Accordion {
  display: block;
  list-style: none;
  padding: 0;
  margin: 0;
}

.spectrum-Accordion-itemIndicator {
  display: block;
  flex-shrink: 0;

  padding-inline-start: var(--spectrum-accordion-icon-gap);
  padding-inline-end: var(--spectrum-accordion-icon-gap);

  transition: transform ease var(--spectrum-global-animation-duration-100);
  box-sizing: content-box;
}

.spectrum-Accordion-item {
  z-index: inherit;
  position: relative;

  display: list-item;
  list-style: none;
  margin: 0;

  border-bottom: var(--spectrum-accordion-item-border-size) solid var(--spectrum-accordion-border-color);
  border-top: var(--spectrum-accordion-item-border-size) solid var(--spectrum-accordion-border-color);

  &.in-accordion:not(:first-of-type) {
    border-top-width: 0;
  }

  &.spectrum-Accordion-item--quiet {
    border-bottom-width: 0;
    border-top-width: 0;

    &:first-of-type {
      border-top-width: 0;
    }
  }
}

.spectrum-Accordion-itemHeading {
  margin: 0;
}

.spectrum-Accordion-itemHeader {
  outline: none;
  position: relative;

  display: flex;
  align-items: center;
  justify-content: flex-start;

  box-sizing: border-box;
  /* left padding takes into account the icon's size as well as the focus state's left border */
  padding-block: var(--spectrum-accordion-item-title-padding-y);
  padding-inline-start: var(--spectrum-accordion-icon-gap);
  padding-inline-end: var(--spectrum-accordion-item-padding);
  margin: 0;

  min-height: var(--spectrum-accordion-item-height-actual);

  font-size: var(--spectrum-global-dimension-font-size-300);
  line-height: var(--spectrum-accordion-item-line-height);

  text-overflow: ellipsis;
  cursor: default;
  font-weight: var(--spectrum-global-font-weight-bold);

  /* reset styling if button element is used */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: inherit;
  font-family: inherit;
  text-align: start;
  width: 100%;
  border-style: solid;
  border-color: transparent;

  &.focus-ring {
    border-radius: var(--spectrum-global-dimension-static-size-100);
    outline: solid 2px var(--spectrum-accordion-item-focus-ring-color);
    outline-offset: -2px;
  }
}

.spectrum-Accordion-item.is-expanded {
  .spectrum-Accordion-itemContent {
    padding: 8px 9px 16px 9px;
  }
}

.spectrum-Accordion-item {
  &.is-expanded {
    > .spectrum-Accordion-itemHeading {
      > .spectrum-Accordion-itemHeader {
        > .spectrum-Accordion-itemIndicator {
          [dir='ltr'] & {
            transform: rotate(90deg);
          }
          [dir='rtl'] & {
            transform: rotate(-90deg);
          }
        }
      }
    }

    > .spectrum-Accordion-itemHeader::after {
      /* No bottom border when expanded, so be less tall */
      height: var(--spectrum-accordion-item-height-actual);
    }

    > .spectrum-Accordion-itemContent {
      display: block;
    }
  }

  &.is-disabled {
    .spectrum-Accordion-itemHeader {
      cursor: default;
    }
  }
}
